package top.healthylife.gateway.platform.zzc.api.config;

import lombok.Data;
import lombok.experimental.Accessors;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Configuration;
import top.healthylife.basics.utils.exception.BusinessException;
import top.healthylife.gateway.core.config.BaseConfig;
import top.healthylife.gateway.dto.annotation.SystemInfo;
import top.healthylife.gateway.dto.annotation.SystemInfoField;

import java.io.Serializable;
import java.util.Base64;

/**
 * @author cl
 * @version 1.0
 * @date 2020/4/10 17:48
 */
@SystemInfo(systemName = "中智诚", shortName = "zzc")
@Data
@Configuration
@Accessors(chain = true)
@ConfigurationProperties(prefix = "system")
public class SystemConfig extends BaseConfig implements Serializable {
    private static final long serialVersionUID = -4735148160159528848L;
    /**
     * 用户名
     */
    @SystemInfoField("用户名")
    private String username ;

    /**
     * 密码
     */
    @SystemInfoField("密码")
    private String password ;

    public String getToken() {
        if (username == null || password == null) {
            throw new BusinessException("账户或密码为空,获取token失败");
        }
        return "Basic " + Base64.getEncoder().encodeToString((this.username + ":" + this.password).getBytes());
    }
}
